from pathlib import Path

files_and_dirs = Path("./hlsobj/hls")

ret = files_and_dirs.glob("*")

header = '''
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Music Player with APlayer</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer@latest/dist/APlayer.min.css">
</head>
<body>
    <div id="aplayer"></div>
    <script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
    <script src="https://cdn.jsdelivr.net/npm/aplayer@latest/dist/APlayer.min.js"></script>
    <script>
        const ap = new APlayer({
    container: document.getElementById('aplayer'),
    audio: [
'''

end = '''
]
});

    </script>
</body>
</html>
'''

maintmp = ""

# 此循环生成子页面的 html，并将其链接到 index.html 中
for ite in ret :
    tmp = "{ name: '"
    tmp = tmp + ite.name + "', "
    tmp = tmp + "url: 'https://47.236.245.52:43210/hls/" + ite.name + "/" + ite.name + ".m3u8', "
    tmp = tmp + "type: 'hls'"
    tmp = tmp + "    },\n"
    
    
    maintmp = maintmp + tmp
    
    
with open("./indextmp.html", mode="w", encoding="utf-8") as f :
    f.write(header + maintmp + end)
